using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Data;

namespace DD.Products
{
    public static class ProductManager
    {

        /// <summary>
        /// Gets Product
        /// </summary>
        /// <param name="ProductId">Unique Product Id</param>
        public static Product GetProduct(int ProductId)
        {
            DataSet ds = new DataSet();
            ds = DD.Data.SQL.ProductManager.GetProduct(ProductId);

            DataRow dr = ds.Tables[0].NewRow();
            dr = ds.Tables[0].Rows[0];

            DD.Products.Product p = new Product();

            p.Cost = Convert.ToDouble(dr["COST"]);
            p.ID = ProductId;
            p.Name = dr["NAME"].ToString();

            p.OnSale = false;
            if ((int)dr["ONSALE"] == 1)
            {
                p.OnSale = true;
            }
            p.Active = false;
            if ((int)dr["ACTIVE"] == 1)
            {
                p.Active = true;
            }
            p.Price = Convert.ToDouble(dr["PRICE"]);
            p.SalePrice = Convert.ToDouble(dr["SALEPRICE"]);
            p.Type = (DD.Products.ProductType)Convert.ToInt32(dr["TYPE"]);

            return p;

        }

        public static int AddProduct(Product product)
        {
            int active = 0;
            if (product.Active == true)
            {
                active = 1;
            }
            int onsale = 0;
            if(product.OnSale == true)
            {
                onsale = 1;
            }
            int NewId = DD.Data.SQL.ProductManager.AddProduct(active, product.Cost, product.Name, onsale, product.Price, product.SalePrice, product.Type, product.Description);

            return NewId;

        }

        public static void AddProductStyle(int productId, int styleId, string dropshipId)
        {
            DD.Data.SQL.ProductManager.AddProductStyle(productId, styleId, dropshipId);

        }

        public static void AddProductCategory(int productId, int catId)
        {
            DD.Data.SQL.ProductManager.AddProductCategory(productId, catId);
        }
    }

}